package me.zk;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @Author: zhang kai
 * @Date: 2022/07/12
 * @Description:
 */
public class Demo1 {
    public static void main(String[] args) {
        Predicate<String> nonEmptyStringPredicate = (s -> !s.isEmpty());
        filter(Arrays.asList("string"),nonEmptyStringPredicate);
    }
    public static <T> List<T> filter(List<T> list, Predicate<T> p) {
        List<T> results = new ArrayList<>();
        for(T s: list){
            if(p.test(s)){
                results.add(s);
            }
        }
        return results;
    }

}
